/** 
* 文 件 名:UploadManageLogic.java
* Copyright (C) 2007-2012:杭州希禾信息技术有限公司 版权所有 
* 创 建 人:刘绍辉
* 日    期:2012-3-12 下午3:36:17
* 修 改 人: 
* 日   期:
* 修改描述:
* 描   述:TODO
*/
package net.seehealth.healthpad.business.uploadmanage;

import java.util.ArrayList;
import java.util.List;

import net.seehealth.healthpad.application.base.BaseLogic;
import net.seehealth.healthpad.application.base.BaseModel;
import net.seehealth.healthpad.business.uploadmanage.service.IUploadManageLogic;
import net.seehealth.healthpad.dataaccess.HealthSqliteHelper;
import net.seehealth.healthpad.model.foodmanage.FoodType;
import net.seehealth.healthpad.model.upload.BloodPressure;
import net.seehealth.healthpad.model.upload.Electrocardio;
import net.seehealth.healthpad.model.upload.FoodRecord;
import net.seehealth.healthpad.model.upload.SportRecord;
import net.seehealth.healthpad.model.upload.Weight;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
/**
 * @className UploadManageLogic
 * @author 刘绍辉
 * @description TODO 需上传数据业务类
 * @date 2012-3-12 下午5:22:54
 */
public class UploadManageLogic extends BaseLogic implements IUploadManageLogic {
	private HealthSqliteHelper helper = null;
	public UploadManageLogic (Context context){
		helper = new HealthSqliteHelper(context);
	}
	@Override
	public List<FoodRecord> getFoodRecordDatas() {
		List<FoodRecord> foodRecords = new ArrayList<FoodRecord>();
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor = db.query("foodrecord", null, null, null, null, null, null);
		for (cursor.moveToFirst();!(cursor.isAfterLast());cursor.moveToNext()) {
			FoodRecord foodRecord = new FoodRecord();
			foodRecord.setFrid(cursor.getInt(cursor.getColumnIndex("frid")));
			foodRecord.setUserID(cursor.getInt(cursor.getColumnIndex("userID")));
			foodRecord.setIntake(cursor.getFloat(cursor.getColumnIndex("intake")));
			foodRecord.setEatTime(cursor.getInt(cursor.getColumnIndex("eatTime")));
			foodRecord.setIntakeEn(cursor.getFloat(cursor.getColumnIndex("intakeen")));
			foodRecord.setFoodCode(cursor.getString(cursor.getColumnIndex("foodCode")));
			foodRecord.setRecordTime(cursor.getString(cursor.getColumnIndex("recordTime")));
			foodRecords.add(foodRecord);
		}
		cursor.close();
		db.close();
		return foodRecords;
	}

	@Override
	public List<SportRecord> getSportRecordDatas() {
		List<SportRecord> sportRecords = new ArrayList<SportRecord>();
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor = db.query("sportrecord", null, null, null, null, null, null);
		for (cursor.moveToFirst();!(cursor.isAfterLast());cursor.moveToNext()) {
			SportRecord sportRecord = new SportRecord();
			sportRecord.setSrid(cursor.getInt(cursor.getColumnIndex("srid")));
			sportRecord.setUserID(cursor.getInt(cursor.getColumnIndex("userID")));
			sportRecord.setSportTime(cursor.getInt(cursor.getColumnIndex("sportTime")));
			sportRecord.setWaste(cursor.getFloat(cursor.getColumnIndex("waste")));
			sportRecord.setSportCode(cursor.getString(cursor.getColumnIndex("sportCode")));
			sportRecord.setRecordTime(cursor.getString(cursor.getColumnIndex("recordTime")));
			sportRecords.add(sportRecord);
		}
		cursor.close();
		db.close();
		return sportRecords;
	}

	@Override
	public List<BloodPressure> getBloodPressureDatas() {
		List<BloodPressure> bloodPressures = new ArrayList<BloodPressure>();
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor = db.query("bloodpressure", null, null, null, null, null, null);
		for (cursor.moveToFirst();!(cursor.isAfterLast());cursor.moveToNext()) {
			BloodPressure bloodPressure = new BloodPressure();
			bloodPressure.setBid(cursor.getInt(cursor.getColumnIndex("bid")));
			bloodPressure.setUserID(cursor.getInt(cursor.getColumnIndex("userID")));
			bloodPressure.setDate(cursor.getString(cursor.getColumnIndex("date")));
			bloodPressure.setBloodpressure(cursor.getFloat(cursor.getColumnIndex("bloodpressure")));
			bloodPressure.setDiastolicpressure(cursor.getFloat(cursor.getColumnIndex("diastolicpressure")));
			bloodPressure.setPulse(cursor.getFloat(cursor.getColumnIndex("pulse")));
			bloodPressure.setYear(cursor.getInt(cursor.getColumnIndex("year")));
			bloodPressure.setMonth(cursor.getString(cursor.getColumnIndex("month")));
			bloodPressure.setWeek(cursor.getInt(cursor.getColumnIndex("week")));
			bloodPressure.setDatafrom(cursor.getInt(cursor.getColumnIndex("datafrom")));
			bloodPressures.add(bloodPressure);
		}
		cursor.close();
		db.close();
		return bloodPressures;
	}

	@Override
	public List<Weight> getWeightDatas() {
		List<Weight> weights = new ArrayList<Weight>();
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor = db.query("weight", null, null, null, null, null, null);
		for (cursor.moveToFirst();!(cursor.isAfterLast());cursor.moveToNext()) {
			Weight weight = new Weight();
			weight.setWid(cursor.getInt(cursor.getColumnIndex("wid")));
			weight.setUserID(cursor.getInt(cursor.getColumnIndex("userID")));
			weight.setDate(cursor.getString(cursor.getColumnIndex("date")));
			weight.setAge(cursor.getInt(cursor.getColumnIndex("age")));
			weight.setBm(cursor.getFloat(cursor.getColumnIndex("bm")));
			weight.setVisceralfat(cursor.getFloat(cursor.getColumnIndex("visceralfat")));
			weight.setBodyfatRate(cursor.getFloat(cursor.getColumnIndex("bodyfatRate")));
			weight.setBodyage(cursor.getInt(cursor.getColumnIndex("bodyage")));
			weight.setSkeletalmuscleRate(cursor.getFloat(cursor.getColumnIndex("skeletalmuscleRate")));
			weight.setWeight(cursor.getFloat(cursor.getColumnIndex("weight")));
			weight.setYear(cursor.getInt(cursor.getColumnIndex("year")));
			weight.setMonth(cursor.getString(cursor.getColumnIndex("month")));
			weight.setWeek(cursor.getInt(cursor.getColumnIndex("week")));
			weight.setDatafrom(cursor.getInt(cursor.getColumnIndex("datafrom")));
			weights.add(weight);
		}
		cursor.close();
		db.close();
		return weights;
	}

	@Override
	public List<Electrocardio> getElectrocardioDatas() {
		List<Electrocardio> electrocardios = new ArrayList<Electrocardio>();
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor = db.query("electrocardio", null, null, null, null, null, null);
		for (cursor.moveToFirst();!(cursor.isAfterLast());cursor.moveToNext()) {
			Electrocardio electrocardio = new Electrocardio();
			electrocardio.setEid(cursor.getInt(cursor.getColumnIndex("eid")));
			electrocardio.setUserID(cursor.getInt(cursor.getColumnIndex("userID")));
			electrocardio.setDate(cursor.getString(cursor.getColumnIndex("date")));
			electrocardio.setIsright(cursor.getString(cursor.getColumnIndex("isright")));
			electrocardio.setHowmany(cursor.getInt(cursor.getColumnIndex("howmany")));
			electrocardio.setHowmanysuccess(cursor.getInt(cursor.getColumnIndex("howmanysuccess")));
			electrocardio.setAhrhear(cursor.getFloat(cursor.getColumnIndex("ahrhear")));
			electrocardio.setPr(cursor.getFloat(cursor.getColumnIndex("pr")));
			electrocardio.setQt(cursor.getFloat(cursor.getColumnIndex("qt")));
			electrocardio.setRvolt(cursor.getFloat(cursor.getColumnIndex("rvolt")));
			electrocardio.setPvolt(cursor.getFloat(cursor.getColumnIndex("pvolt")));
			electrocardio.setAhrhear(cursor.getFloat(cursor.getColumnIndex("ahrhear")));
			electrocardio.setTvolt(cursor.getInt(cursor.getColumnIndex("tvolt")));
			electrocardio.setSvolt(cursor.getFloat(cursor.getColumnIndex("svolt")));
			electrocardio.setYear(cursor.getInt(cursor.getColumnIndex("year")));
			electrocardio.setMonth(cursor.getString(cursor.getColumnIndex("month")));
			electrocardio.setWeek(cursor.getInt(cursor.getColumnIndex("week")));
			electrocardio.setDatafrom(cursor.getInt(cursor.getColumnIndex("datafrom")));
			electrocardios.add(electrocardio);
		}
		cursor.close();
		db.close();
		return electrocardios;
	}
	@Override
	public boolean saveFoodRecordDatas(FoodRecord foodRecord) {
		boolean bool = false;
		SQLiteDatabase db = helper.getWritableDatabase();
		ContentValues  values = new ContentValues();
		values.put("userID", foodRecord.getUserID());
		values.put("intake", foodRecord.getIntake());
		values.put("eatTime", foodRecord.getEatTime());
		values.put("intakeen", foodRecord.getIntakeEn());
		values.put("foodCode", foodRecord.getFoodCode());
		values.put("recordTime", foodRecord.getRecordTime());
		long num = db.insert("foodrecord", null, values);
		if(num!=0){
			bool = true;
		}
		return bool;
	}

	@Override
	public boolean saveSportRecordDatas(SportRecord sportRecord) {
		boolean bool = false;
		SQLiteDatabase db = helper.getWritableDatabase();
		ContentValues  values = new ContentValues();
		values.put("userID", sportRecord.getUserID());
		values.put("sportTime", sportRecord.getSportTime());
		values.put("waste", sportRecord.getWaste());
		values.put("sportCode", sportRecord.getSportCode());
		values.put("recordTime", sportRecord.getRecordTime());
		long num = db.insert("sportrecord", null, values);
		if(num!=0){
			bool = true;
		}
		return bool;
	}

	@Override
	public boolean saveBloodPressureData(BloodPressure bloodPressure) {
		boolean bool = false;
		SQLiteDatabase db = helper.getWritableDatabase();
		ContentValues  values = new ContentValues();
		values.put("userID", bloodPressure.getUserID());
		values.put("date", bloodPressure.getDate());
		values.put("bloodpressure", bloodPressure.getBloodpressure());
		values.put("diastolicpressure", bloodPressure.getDiastolicpressure());
		values.put("pulse", bloodPressure.getPulse());
		values.put("year", bloodPressure.getYear());
		values.put("month", bloodPressure.getMonth());
		values.put("week", bloodPressure.getWeek());
		values.put("datafrom", bloodPressure.getDatafrom());
		long num = db.insert("bloodpressure", null, values);
		if(num!=0){
			bool = true;
		}
		return bool;
	}

	@Override
	public boolean saveWeightData(Weight weight) {
		boolean bool = false;
		SQLiteDatabase db = helper.getWritableDatabase();
		ContentValues  values = new ContentValues();
		values.put("userID", weight.getUserID());
		values.put("bmi", weight.getBmi());
		values.put("date", weight.getDate());
		values.put("age", weight.getAge());
		values.put("bm", weight.getBm());
		values.put("visceralfat", weight.getVisceralfat());
		values.put("bodyfatRate", weight.getBodyfatRate());
		values.put("bodyage", weight.getBodyage());
		values.put("skeletalmuscleRate", weight.getSkeletalmuscleRate());
		values.put("weight", weight.getWeight());
		values.put("year", weight.getYear());
		values.put("month", weight.getMonth());
		values.put("week", weight.getWeek());
		values.put("datafrom", weight.getDatafrom());
		long num = db.insert("weight", null, values);
		if(num!=0){
			bool = true;
		}
		return bool;
	}

	@Override
	public boolean saveElectrocardioData(Electrocardio electrocardio) {
		boolean bool = false;
		SQLiteDatabase db = helper.getWritableDatabase();
		ContentValues  values = new ContentValues();
		values.put("userID", electrocardio.getUserID());
		values.put("isright", electrocardio.getIsright());
		values.put("howmany", electrocardio.getHowmany());
		values.put("howmanysuccess", electrocardio.getHowmanysuccess());
		values.put("ahrhear", electrocardio.getAhrhear());
		values.put("pr", electrocardio.getPr());
		values.put("qt", electrocardio.getQt());
		values.put("rvolt", electrocardio.getRvolt());
		values.put("pvolt", electrocardio.getPvolt());
		values.put("tvolt", electrocardio.getTvolt());
		values.put("svolt", electrocardio.getSvolt());
		values.put("year", electrocardio.getYear());
		values.put("month", electrocardio.getMonth());
		values.put("week", electrocardio.getWeek());
		values.put("datafrom", electrocardio.getDatafrom());
		long num = db.insert("electrocardio", null, values);
		if(num!=0){
			bool = true;
		}
		return bool;
	}

	@Override
	public void removeFoodRecordDatas(List<FoodRecord> foodRecords) {
		SQLiteDatabase db = helper.getWritableDatabase();
		if(foodRecords!=null&&foodRecords.size()!=0){
			for (int j = 0; j < foodRecords.size(); j++) {
				FoodRecord fr = foodRecords.get(j);
				db.delete("foodrecord", "frid=?", new String[]{fr.getFrid()+""});
			}
		}
		db.close();
	}

	@Override
	public void removeSportRecordDatas(List<SportRecord> sportRecords) {
		SQLiteDatabase db = helper.getWritableDatabase();
		if(sportRecords!=null&&sportRecords.size()!=0){
			for (int j = 0; j < sportRecords.size(); j++) {
				SportRecord fr = sportRecords.get(j);
				db.delete("sportrecord", "srid=?", new String[]{fr.getSrid()+""});
			}
		}
		db.close();
	}

	@Override
	public void removeBloodPressureDatas(List<BloodPressure> bloodPressures) {
		SQLiteDatabase db = helper.getWritableDatabase();
		if(bloodPressures!=null&&bloodPressures.size()!=0){
			for (int j = 0; j < bloodPressures.size(); j++) {
				BloodPressure fr = bloodPressures.get(j);
				db.delete("bloodpressure", "bid=?", new String[]{fr.getBid()+""});
			}
		}
		db.close();
	}

	@Override
	public void removeWeightDatas(List<Weight> weights) {
		SQLiteDatabase db = helper.getWritableDatabase();
		if(weights!=null&&weights.size()!=0){
			for (int j = 0; j < weights.size(); j++) {
				Weight fr = weights.get(j);
				db.delete("weight", "wid=?", new String[]{fr.getWid()+""});
			}
		}
		db.close();
	}

	@Override
	public void removeElectrocardioDatas(List<Electrocardio> electrocardios) {
		SQLiteDatabase db = helper.getWritableDatabase();
		if(electrocardios!=null&&electrocardios.size()!=0){
			for (int j = 0; j < electrocardios.size(); j++) {
				Electrocardio fr = electrocardios.get(j);
				db.delete("electrocardio", "eid=?", new String[]{fr.getEid()+""});
			}
		}
		db.close();
	}

	@Override
	public BaseModel queryDataByUserId(int userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BaseModel queryDataById(int pk) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean addData(BaseModel model) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean modifData(BaseModel model) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean modifData(ArrayList<BaseModel> datas) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean uploadBloodPressuredata() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean uploadWeightData() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean uploadElectrocardioData() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean uploadSportRecordData() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean uploadFoodRecordData() {
		// TODO Auto-generated method stub
		return false;
	}
}
